Skip to content

[Kotlin][jvm-spring-restclient] make nullableReturnType type bound conditional in ApiClient#23657

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
takkiraz:fix/kotlin-spring-restclient-nullable-apiclient
Apr 30, 2026
Merged

[Kotlin][jvm-spring-restclient] make nullableReturnType type bound conditional in ApiClient#23657
wing328 merged 1 commit intoOpenAPITools:masterfrom
takkiraz:fix/kotlin-spring-restclient-nullable-apiclient

Conversation

@takkiraz
Copy link
Copy Markdown
Contributor

@takkiraz takkiraz commented Apr 29, 2026

Fixes #23654

PR #23613 unconditionally relaxed the type bound from T : Any to T : Any? in ApiClient.kt.mustache for jvm-spring-restclient. This breaks compilation with Spring Boot 4 / Spring Framework 7, where stricter nullability handling rejects nullable bounds on RestClient.ResponseSpec.toEntity().

Make the relaxation conditional on the nullableReturnType option:

Config T bound Notes
Default (nullableReturnType=false) T : Any Identical to pre-#23613
nullableReturnType=true T : Any? Preserves the #23613 NPE fix

Also restores I bound to Any everywhere (request bodies are never nullable) and removes the unnecessary as Any cast in nullableBody.

Verification:

  • Reproduced the failure on master with Spring Boot 4.0.6 + Kotlin 2.3.21
  • Confirmed this fix resolves the compilation error
  • Original NPE fix from [kotlin][jvm-spring-restclient] honour nullableReturnType in body access #23613 remains intact (regression test in nullable-return sample passes)
  • ./bin/generate-samples.sh bin/configs/kotlin-*.yaml — 112 generators, zero drift
  • ./bin/utils/export_docs_generators.sh — no doc changes

Note: nullableReturnType=true combined with Spring Boot 4 still has a separate compatibility issue with Spring Framework 7's toEntity() bounds. That requires a different architectural approach and is being considered as a follow-up; out of scope for this regression fix.

cc @wing328 @stefankoppier @karismann @Zomzog @andrewemery @4brunu @yutaka0m @e5l @dennisameling

PR checklist


Summary by cubic

Conditionally relax the response type bound in jvm-spring-restclient ApiClient.kt.mustache based on nullableReturnType. Restores Spring Boot 4 / Spring Framework 7 compatibility while keeping the nullable-return NPE fix.

  • Bug Fixes
    • Default (nullableReturnType=false): T : Any; when true: T : Any?, avoiding RestClient.ResponseSpec.toEntity() bound errors.
    • Restore request body bound to non-null (I : Any) and remove the unnecessary as Any cast.
    • Verified: samples build with Spring Boot 4 + Kotlin 2.3.21; nullable-return regression passes; no doc or sample drift.

Written for commit c79ab9b. Summary will update on new commits. Review in cubic

…nditional in ApiClient

Fixes OpenAPITools#23654

PR OpenAPITools#23613 unconditionally relaxed the type bound from `T : Any` to
`T : Any?` in ApiClient.kt.mustache for jvm-spring-restclient. This
breaks compilation with Spring Boot 4 / Spring Framework 7, where
stricter nullability handling rejects nullable bounds on
RestClient.ResponseSpec.toEntity().

Make the relaxation conditional on the nullableReturnType option:
- Default (nullableReturnType=false): T : Any (identical to pre-OpenAPITools#23613)
- nullableReturnType=true: T : Any? (preserves the OpenAPITools#23613 NPE fix)

Also restores I bound to Any everywhere (request bodies are never
nullable) and removes the unnecessary `as Any` cast in nullableBody.
@takkiraz takkiraz changed the title [kotlin][jvm-spring-restclient] make nullableReturnType type bound conditional in ApiClient [Kotlin][jvm-spring-restclient] make nullableReturnType type bound conditional in ApiClient Apr 29, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

@wing328 wing328 merged commit 1e8ef54 into OpenAPITools:master Apr 30, 2026
70 checks passed
@wing328 wing328 added this to the 7.23.0 milestone Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Regression of 7.21.0 -> 7.22.0 Generated Kotlin code does not compile

2 participants